package com.mhkj.base.amount.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.mhkj.base.amount.dao.ExamineStandardDao;
import com.mhkj.base.amount.entity.ExamineStandard;
import com.mhkj.base.amount.service.ExamineStandardService;
import com.mics.core.common.componet.Pagination;
import com.mics.core.system.base.service.impl.BaseServiceImpl;

/**
 * 考核标准
 */
@Service
public class ExamineStandardServiceImpl extends BaseServiceImpl<ExamineStandard>
		implements ExamineStandardService {

	@Autowired
	private ExamineStandardDao examineStandardDao;

	@Autowired
	public void setExamineStandardDao(ExamineStandardDao ExamineStandardDao) {
		super.setBaseRepository(ExamineStandardDao);
	}

	@Override
	public Pagination<ExamineStandard> findPage(ExamineStandard entity, Integer pageIndex, Integer pageSize) {
		Specification<ExamineStandard> spec = new Specification<ExamineStandard>() {
			/**
			 * 序号
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public Predicate toPredicate(Root<ExamineStandard> root, CriteriaQuery<?> query,
					CriteriaBuilder criteriaBuilder) {
				List<Predicate> lstPredicates = new ArrayList<Predicate>();
				Predicate[] arrayPredicates = new Predicate[lstPredicates.size()];

				return criteriaBuilder.and(lstPredicates.toArray(arrayPredicates));
			}
		};
		PageRequest pageable = PageRequest.of(pageIndex, pageSize, Sort.Direction.ASC, "id");
		Page<ExamineStandard> pageT = examineStandardDao.findAll(spec, pageable);
		Pagination<ExamineStandard> pagination = new Pagination<ExamineStandard>();
		pagination.setTotal(examineStandardDao.count(spec));
		pagination.setData(pageT.getContent());
		return pagination;
	}



}
